{% extends 'base.html' %}

{% block title %}{{ need.title }} - 校园技能交换平台{% endblock %}

{% block content %}
<div class="card">
    <div class="card-header">
        <div class="d-flex justify-content-between align-items-center">
            <h2 class="mb-0">{{ need.title }}</h2>
            {% if user == need.requester %}
            <div>
                <a href="{% url 'listings:need_edit' need.pk %}" class="btn btn-outline-primary">
                    编辑
                </a>
            </div>
            {% endif %}
        </div>
    </div>
    <div class="card-body">
        <div class="row">
            <div class="col-md-8">
                <h5 class="card-title">需求描述</h5>
                <p class="card-text">{{ need.description|linebreaks }}</p>
                
                {% if need.tags %}
                <div class="mb-3">
                    <h5>标签</h5>
                    {% for tag in need.tags.split %}
                    <span class="badge bg-secondary me-1">{{ tag }}</span>
                    {% endfor %}
                </div>
                {% endif %}
            </div>
            <div class="col-md-4">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">需求信息</h5>
                        <ul class="list-unstyled">
                            <li class="mb-2">
                                <strong>分类：</strong>
                                {{ need.get_category_display }}
                            </li>
                            <li class="mb-2">
                                <strong>回报方式：</strong>
                                {{ need.get_reward_type_display }}
                            </li>
                            {% if need.reward_description %}
                            <li class="mb-2">
                                <strong>回报说明：</strong>
                                {{ need.reward_description }}
                            </li>
                            {% endif %}
                            <li class="mb-2">
                                <strong>发布时间：</strong>
                                {{ need.created_at|date:"Y-m-d H:i" }}
                            </li>
                            <li class="mb-2">
                                <strong>最后更新：</strong>
                                {{ need.updated_at|date:"Y-m-d H:i" }}
                            </li>
                        </ul>
                    </div>
                </div>

                <div class="card mt-3">
                    <div class="card-body">
                        <h5 class="card-title">发布者信息</h5>
                        <ul class="list-unstyled">
                            <li class="mb-2">
                                <strong>用户名：</strong>
                                {{ need.requester.username }}
                            </li>
                            <li class="mb-2">
                                <strong>用户类型：</strong>
                                {{ need.requester.get_user_type_display }}
                            </li>
                            {% if need.requester.college %}
                            <li class="mb-2">
                                <strong>学院：</strong>
                                {{ need.requester.college }}
                            </li>
                            {% endif %}
                            {% if need.requester.major %}
                            <li class="mb-2">
                                <strong>专业/部门：</strong>
                                {{ need.requester.major }}
                            </li>
                            {% endif %}
                        </ul>
                        {% if user.is_authenticated and user != need.requester %}
                        <button type="button" class="btn btn-primary w-100" data-bs-toggle="modal" data-bs-target="#contactModal">
                            联系发布者
                        </button>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{% if user.is_authenticated and user != need.requester %}
<!-- 联系发布者的模态框 -->
<div class="modal fade" id="contactModal" tabindex="-1" aria-labelledby="contactModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="contactModalLabel">联系 {{ need.requester.username }}</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form method="post" action="{% url 'listings:contact_requester' need.pk %}">
                    {% csrf_token %}
                    <div class="mb-3">
                        <label for="message" class="form-label">留言内容</label>
                        <textarea class="form-control" id="message" name="message" rows="4" required></textarea>
                    </div>
                    <div class="d-grid">
                        <button type="submit" class="btn btn-primary">发送留言</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endif %}
{% endblock %} 